home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
extra
/
pro13
/
strncpy.c
< prev
next >
Wrap
Text File
|
1993-02-01
|
662b
|
33 lines
/*
strncpy.C
Copyright (C) 1993, Geoff Friesen B.Sc.
All rights reserved.
*/
#define INCL_STRNCPY
char *strncpy (char *dest, const char *src, size_t maxlen)
{
_ES = _DS;
asm cld
_SI = _DI = (unsigned) src;
_BX = _CX = (unsigned) maxlen;
asm mov al, 0
asm repnz scasb; /* search for null terminator */
_BX -= _CX; /* bx is actual length of string */
_DI = (unsigned) dest;
asm xchg cx, bx /* bx is number of nulls to pad */
asm repz movsb
_CX = _BX; /* cx is number of nulls to pad */
asm repz stosb; /* pad with nulls */
_AX = (unsigned) dest; /* return destination */
}